import React from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { Link } from 'react-router';

import * as Util from '../common/Util';
import * as MessageActions from '../actions/MessageActions';
import Container from '../components/Container';

class MessageDetailApp extends React.Component {

  constructor () {
    super();   
  }

  static propTypes = {
    
  }

  getMessage(){
    let { message } = this.props;
    let mid = this.props.location.query.id;
    let messageDetail = {};
    if(message && message.allmessage && message.allmessage.length){
      for(let i =0 ,len = message.allmessage.length; i < len; i++){
        let messageItem = message.allmessage[i];
        if (messageItem.id === mid) {
          messageDetail = messageItem;
          break;
        }
      }
    }
    return messageDetail;
  }

  render() {

    let messageDetail = this.getMessage();
    
    return (
          <Container 
              isGoBack={true} 
              isHeader={true} 
              isFooter={false}  
              headerTitle={"系统消息"}>

             <div className="messagesys-container">
               <h5 className="text-primary">
                  { messageDetail.title }
               </h5>
               <label className="text-primary">
                  {Util.DateFormater(messageDetail.createdate, "yyyy-MM-dd")}
               </label>
               <img src={messageDetail.pic} className="img-responsive"/>
               <p dangerouslySetInnerHTML={{__html: messageDetail.content}} >
               </p>
             </div>
          </Container>
    );
  }
}

export default connect(state => ({
    message : state.message
}), dispatch => ({
    messageAction: bindActionCreators(MessageActions, dispatch)
}))(MessageDetailApp);
